/*
 * @Author: dvlproad
 * @Date: 2023-10-23 16:48:06
 * @LastEditors: dvlproad
 * @LastEditTime: 2023-10-31 18:54:24
 * @Description: 
 */
import 'dart:math';

import 'package:flutter/material.dart';

import '../test_web_controller_util.dart';

class TSMineHomeViewController extends StatefulWidget {
  final String userId;
  const TSMineHomeViewController({super.key, required this.userId});

  @override
  State<TSMineHomeViewController> createState() =>
      _TSMineHomeViewControllerState();
}

class _TSMineHomeViewControllerState extends State<TSMineHomeViewController> {
  @override
  Widget build(BuildContext context) {
    String title = "游戏";
    int randomNumber = Random().nextInt(1000);
    String randomString = randomNumber.toString().padLeft(3, '0');
    Map<String, dynamic> urlParams = {
      "title": title,
      "userId": "1001",
      "randomNum": randomString,
    };
    String mpString = "${title}_$randomString";

    String pageTitle = "用户id_${widget.userId}";

    return Scaffold(
      appBar: AppBar(
        title: Text(pageTitle),
      ),
      body: Center(
        child: Stack(
          children: [
            ListView(
              children: [
                _renderItem(
                  '返回小程序',
                  alignment: Alignment.centerLeft,
                  onTap: () async {
                    Navigator.pop(context);
                  },
                ),
                _renderItem(
                  '进入小程序:$mpString',
                  alignment: Alignment.centerLeft,
                  onTap: () async {
                    ShareWebViewController.goTSWebViewJSPage(context,
                        urlParams: urlParams, methodTpye: 0);
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  _renderItem(
    String title, {
    required Function onTap,
    AlignmentGeometry alignment = Alignment.center,
  }) {
    return InkWell(
      onTap: () {
        onTap();
      },
      child: Column(
        children: [
          Container(
            height: 44,
            alignment: alignment,
            child: Text(title),
          ),
          Container(
            color: Colors.black12,
            height: 0.5,
          )
        ],
      ),
    );
  }
}
